//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.cn.common.utils.excel;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class ExportExcelZip {
    public ExportExcelZip() {
    }

    public static void downloadExcelForZip(HttpServletResponse response, Map<String, XSSFWorkbook> workbookMap, String zipName) throws IOException {
        ZipOutputStream out = null;

        try {
            response.setContentType("application/*");
            response.setHeader("content-disposition", "attachment;filename=" + new String(zipName.getBytes("gb2312"), "ISO8859-1"));
            response.setCharacterEncoding("UTF-8");
            out = new ZipOutputStream(response.getOutputStream());
            Iterator var4 = workbookMap.keySet().iterator();

            while(var4.hasNext()) {
                String fileName = (String)var4.next();
                XSSFWorkbook workbook = (XSSFWorkbook)workbookMap.get(fileName);
                ZipEntry entry = new ZipEntry(fileName);
                out.putNextEntry(entry);
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                workbook.write(bos);
                bos.writeTo(out);
                out.closeEntry();
            }
            out.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (out != null) {
                out.close();
            }

        }
    }
}
